package cn.chi.base.service.impl;

import cn.chi.base.service.ILoginService;
import cn.chi.org.domain.Employee;
import cn.chi.org.mapper.EmployeeMapper;
import cn.chi.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements ILoginService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public AjaxResult login(Employee employee) {
        // 通过查询数据库验证该用户是否注册
        Employee empDB = employeeMapper.loadById(employee.getId());
        if(empDB==null){
            // 该用户未注册
            throw  new RuntimeException("用户不存在");
        }
        if (!employee.getUsername().equals(empDB.getUsername())){
            throw  new RuntimeException("用户名或密码错误");
        }
        if (!employee.getPassword().equals(empDB.getPassword())){
            throw  new RuntimeException("用户名或密码错误");
        }
        return AjaxResult.me();
    }
}
